


  const API_HEAD = `https://techcherry.cn/testguoyuanapi/`; 

  var GetQueryString =(name)=>{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return unescape(r[2]); return 'null';
};

var decodeurl =(str)=>{
  var s = "";
  if (str.length == 0) return "";
  s = str.replace(/&amp;/g, "&");
  s = s.replace(/&lt;/g, "<");
  s = s.replace(/&gt;/g, ">");
  s = s.replace(/&nbsp;/g, " ");
  s = s.replace(/&#39;/g, "\'");
  s = s.replace(/&quot;/g, "\"");
  return s;  
}

var formatDate = (date) => {
  return `${date.getFullYear()}.${date.getMonth() + 1}.${date.getDate()} ${date.getHours() > 9 ? date.getHours() : "0" + date.getHours()}:${date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes()}`;
}


var isBase64=(str)=>
 {
 return str.indexOf('data:image')>-1; 
}

//去重
var uniq=(array)=>{
  var temp = []; //一个新的临时数组
  array.forEach(x=>{
    if(temp.indexOf(Number(x) ) == -1)  temp.push(Number(x));
    console.log('uniq',temp);

  })
  
  return temp;
}





var showAlert = (wrap,content,id,type)=>{
  
  wrap.append(` <div id="${id}" class="alert alert-${type}">
  <a href="#" class="close" data-dismiss="alert">&times;</a>
  <strong>提示！</strong>${content}  </div>`)
  $(`#${id}`).alert();
}



var checkPhone=(phone)=>{
  var re =/^[1][3,4,5,7,8][0-9]{9}$/;
  return re.test(phone)
}

function isIPhoneX(){
  
  
   if (screen.height == 812 && screen.width == 375){
       //是iphoneX 
       console.log('是iphoneX/XS 系列');
     return true;
     }else{
          //不是iphoneX
          return false; 
         } }


//默认GET方法
var fstHttps =(url,data,succ,type)=>{
  console.log(url,'fsturl');
  
    $.ajax({
            url,
            type:type?type:'POST',
            //  beforeSend:res=>{
            //   res.setRequestHeader("token",'safjksdhfjksdbngjksdg' );
            // },
            data,

            success: function (res) {
              succ&&succ(JSON.parse(res))
            },
            complete:res=>{
            }
        })
}





var Https =(url,data,succ,type,fail,isasync)=>{

  var senddata={isfen:1, token: $.cookie('token'),buid:$.cookie('userid') }
    if (!senddata.token) { 
      $.cookie('token','')
      $.cookie('userid','')
      localStorage.removeItem('token')
      localStorage.removeItem('userid')
      window.location.href = './login.html'; return
    
    }
   for(var k in data){
     senddata[k] = data[k]
   }
  //  console.log(senddata,'senddata');
   
    $.ajax({
            url,
            type:type?type:'POST',
            data:senddata,
            async:isasync=='false'?!1:!0,
            // beforeSend:res=>{
            //   res.setRequestHeader("userid",$.cookie('userid') );
            // },
            success: function (res) {
              succ&&succ(JSON.parse(res))
            },
           
            complete: function (res) {
              console.log('complete--'+url,res);
              if(res.status!=200){
                fail&&fail(JSON.parse(res.responseText))
              }
            },
        })
}

var excelHttps = (url, data, succ, type, fail, isasync) => {
  var senddata = { token: $.cookie('token') }
  if (!senddata.token) { window.location.href = './login.html'; return }

  for (var k in data) {
    senddata[k] = data[k]
  }
  console.log(senddata, 'senddata');

  $.ajax({
    url,
    type: type ? type : 'POST',
    data: senddata,
    async: isasync == 'false' ? !1 : !0,
    // beforeSend:res=>{
    //   res.setRequestHeader("token",$.cookie('token') );
    // },
    success: function (res) {
      succ && succ(res)
    },

    complete: function (res) {
      if (res.status != 200) {
        fail && fail(JSON.parse(res.responseText))
      }
    },
  })
}

var formatDate = (date)=>{
 return `${date.getFullYear()}.${date.getMonth()+1}.${date.getDate()} ${date.getHours()>9?date.getHours():"0"+date.getHours()}:${date.getMinutes()>9?date.getMinutes():'0'+date.getMinutes()}`;
}

var formatDate1 = (sd)=>{
  return sd.getFullYear()+"-"+("0" + (sd.getMonth() + 1)).slice(-2)+"-"+("0" + sd.getDate()).slice(-2);
 }

// 家具


var getlist = (data,succ)=>{
  Https(`${API_HEAD}orders/bk_getlist1`
  ,data,res=>{
    succ&&succ(res)
  })
}

var apply_getlist = (data,succ)=>{
  Https(`${API_HEAD}apply/bk_getlist`
  ,data,res=>{
    succ&&succ(res)
  })
}

var apply_getelist = (succ)=>{
  Https(`${API_HEAD}apply/bk_getexportlist`
  ,{},res=>{
    succ&&succ(res)
  })
}

var account_getlist = (id,succ)=>{
  Https(`${API_HEAD}account/bk_getlist`
  ,{shopid:id},res=>{
    succ&&succ(res)
  })
}

var apply_check = (data,succ)=>{
  Https(`${API_HEAD}apply/bk_check`
  ,data,res=>{
    succ&&succ(res)
  })
}

var apply_getd = (id,succ)=>{
  Https(`${API_HEAD}apply/bk_getdetail`
  ,{id},res=>{
    succ&&succ(res)
  })
}


var getuserlist = (data,succ)=>{
  Https(`${API_HEAD}users/bk_getuserlist`
  ,data,res=>{
    succ&&succ(res)
  })
}

var 导出用户列表 = (succ)=>{
  Https(`${API_HEAD}users/bk_getuserliste`
  ,{},res=>{
    succ&&succ(res)
  })
}

var 获取全部商户列表 = (succ)=>{
  Https(`${API_HEAD}account/bk_getshoplist`
  ,{},res=>{
    succ&&succ(res)
  })
}

var 获取全部奖品 = (succ)=>{
  Https(`${API_HEAD}score/bk_getgiftlist`
  ,{},res=>{
    succ&&succ(res)
  })
}

var 获取统计 = (succ)=>{
  Https(`${API_HEAD}score/bk_gettongjilist`
  ,{},res=>{
    succ&&succ(res)
  })
}

var 获取全部积分抽奖 = (succ)=>{
  Https(`${API_HEAD}users/bk_getmygiftlistscore`
  ,{},res=>{
    succ&&succ(res)
  })
}

var 获取小票列表 = (data,succ)=>{
  Https(`${API_HEAD}users/bk_getticketlist`
  ,data,res=>{
    succ&&succ(res)
  })
}

var 获取抽奖列表 = (data,succ)=>{
  Https(`${API_HEAD}score/bk_getlotterylist`
  ,data,res=>{
    succ&&succ(res)
  })
}

var 获取我的奖品列表 = (data,succ)=>{
  Https(`${API_HEAD}users/bk_getmygiftlist`
  ,data,res=>{
    succ&&succ(res)
  })
}

var 获取随赠奖品列表 = (succ)=>{
  Https(`${API_HEAD}users/bk_getfreegiftlist`
  ,{},res=>{
    succ&&succ(res)
  })
}
var 修改随赠奖品库存 = (kc,id,succ)=>{
  Https(`${API_HEAD}users/bk_freegiftsetkc`
  ,{id,kc},res=>{
    succ&&succ(res)
  })
}

var 修改抽奖库存 = (kc,id,succ)=>{
  Https(`${API_HEAD}score/bk_lotterysetkc`
  ,{id,kc},res=>{
    succ&&succ(res)
  })
}

var 删除抽奖 = (id,succ)=>{
  Https(`${API_HEAD}score/bk_dellottery`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var 获取中奖记录 = (data,succ)=>{
  Https(`${API_HEAD}lottery/bk_getaward`
  ,data,res=>{
    succ&&succ(res)
  })
}





var 添加账号 = (data,succ)=>{
  Https(`${API_HEAD}account/add`
  ,data,res=>{
    succ&&succ(res)
  })
}

var 删除审核记录 = (id,succ)=>{
  Https(`${API_HEAD}apply/bk_del`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var 删除账号 = (id,succ)=>{
  Https(`${API_HEAD}account/bk_del`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var 删除信息 = (id,succ)=>{
  Https(`${API_HEAD}users/bk_delinfo`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var 解绑 = (id,succ)=>{
  Https(`${API_HEAD}users/bk_jiebang`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var 获取设置 = (succ)=>{
  Https(`${API_HEAD}users/getsettings`
  ,{},res=>{
    succ&&succ(res)
  })
}

var 编辑设置 = (data,succ)=>{
  Https(`${API_HEAD}users/settings_edit`
  ,data,res=>{
    succ&&succ(res)
  })
}




var getexportlist = (data,succ)=>{
  Https(`${API_HEAD}orders/bk_getexportlist`
  ,data,res=>{
    succ&&succ(res)
  })
}

var getnopayexportlist = (succ)=>{
  Https(`${API_HEAD}users/agent_search`
  ,{},res=>{
    succ&&succ(res)
  })
}

var test1 = (json,succ)=>{
  Https(`${API_HEAD}login/testjsons`
  ,{json},res=>{
    succ&&succ(res)
  })
}


var xxxlogin = (data,succ)=>{
  fstHttps(`${API_HEAD}login/bklogin`
  ,data,res=>{
    succ&&succ(res)
  },'POST')
}





// 房间






var LoginAfter = (succ)=>{

  Https(`${API_HEAD}users/login/after`
  ,JSON.stringify({'data':{'returnProfile':!0}}) ,res=>{
    succ&&succ(res)
  })
}







  







